package practice1_100;

public class Practice538 {
    int sum=0;//用来存储便利的值
    public TreeNode convertBST(TreeNode root) {
        //约束条件
        if (root == null) return null;
        //右边
        convertBST(root.right);
        //根

        sum+=root.val;
        root.val=sum;
        //左边
        convertBST(root.left);



        return root;

    }

    public static void main(String[] args) {
        //[4,1,6,0,2,5,7]
        TreeNode a= new Practice538().convertBST(new TreeNode(4, new TreeNode(1, new TreeNode(0), new TreeNode(2)), new TreeNode(6, new TreeNode(5), new TreeNode(7))));
        System.out.println(a);
    }
}
